#pragma once
#include"hash.hpp"

namespace xhy
{
	template<class K>
	struct SetOfT
	{
		const K& operator()(const K& key) { return key; }
	};

	template<class K, class Hash = Hashfunc<K>>
	class unordered_set
	{
		typedef HashTable<K, const K, SetOfT<K>, Hash> HashTable;
	public:
		typedef typename HashTable::Iterator iterator;
		typedef typename HashTable::Const_Iterator const_iterator;
	public:
		std::pair<iterator, bool> insert(const K& key) { return _hash.insert(key); }
		bool erase(const K& key) { return _hash.erase(key); }
		bool Find(const K& key) { return _hash.Find(key); }

		iterator begin()
		{
			return _hash.Begin();
		}

		iterator end()
		{
			return _hash.End();
		}

		const_iterator begin() const
		{
			return _hash.Begin();
		}

		const_iterator end() const
		{
			return _hash.End();
		}

	private:
		HashTable _hash;
	};

	void func(const unordered_set<int>& s)
	{
		unordered_set<int>::const_iterator it = s.begin();
		while (it != s.end())
		{
			std::cout << *it << " ";
			++it;
		}
		std::cout << std::endl;
	}

	void test_uset()
	{
		unordered_set<int> uset;
		uset.insert(10);
		uset.insert(64);
		uset.insert(32);
		uset.insert(322);
		uset.insert(345);

		func(uset);

		unordered_set<int>::iterator it = uset.begin();
		while (it != uset.end())
		{
			//*it += 1;
			std::cout << *it << " ";
			++it;
		}
		std::cout << std::endl;
	}
}